// <editor-fold defaultstate="collapsed" desc="GNU GPLv3 Header">
/*
 * File:   DecompositionHPF.java
 *
 * Copyright (C) 2013 Robert Antoni Buj Gelonch <rbuj@uoc.edu>
 * Copyright (C) 2013 David Megias Jimenez <dmegias@uoc.edu>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
// </editor-fold>
package uoc.libwavelets.Daubechies;

// <editor-fold defaultstate="collapsed" desc="imports">
import uoc.libfilter.DigitalFilter.*;
// </editor-fold>

/**
 *
 * @author Robert Antoni Buj Gelonch <rbuj@uoc.edu>
 * @version 1.0
 * @since 2013-08-15
 */
public final class DecompositionHPF extends DigitalFilterShort {

    // Python code for getting coefficients:
    // from pywt import Wavelet
    // [lo_d, hi_d, lo_r, hi_r] = Wavelet('db2').filter_bank
    // print hi_d
    /**
     * Daubechies coefficients of the 2nd order Decomposition HPF
     */
    private static Double[] db2 = {
        -0.48296291314469025, 0.836516303737469, -0.22414386804185735,
        -0.12940952255092145
    };
    /**
     * Daubechies coefficients of the 3rd order Decomposition HPF
     */
    private static Double[] db3 = {
        -0.3326705529509569, 0.8068915093133388, -0.4598775021193313,
        -0.13501102001039084, 0.08544127388224149, 0.035226291882100656
    };
    /**
     * Daubechies coefficients of the 4th order Decomposition HPF
     */
    private static Double[] db4 = {
        -0.23037781330885523, 0.7148465705525415, -0.6308807679295904,
        -0.02798376941698385, 0.18703481171888114, 0.030841381835986965,
        -0.032883011666982945, -0.010597401784997278
    };
    /**
     * Daubechies coefficients of the 5th order Decomposition HPF
     */
    private static Double[] db5 = {
        -0.160102397974125, 0.6038292697974729, -0.7243085284385744,
        0.13842814590110342, 0.24229488706619015, -0.03224486958502952,
        -0.07757149384006515, -0.006241490213011705, 0.012580751999015526,
        0.003335725285001549
    };
    /**
     * Daubechies coefficients of the 6th order Decomposition HPF
     */
    private static Double[] db6 = {
        -0.11154074335008017, 0.4946238903983854, -0.7511339080215775,
        0.3152503517092432, 0.22626469396516913, -0.12976686756709563,
        -0.09750160558707936, 0.02752286553001629, 0.031582039318031156,
        0.0005538422009938016, -0.004777257511010651, -0.00107730108499558
    };
    /**
     * Daubechies coefficients of the 7th order Decomposition HPF
     */
    private static Double[] db7 = {
        -0.07785205408506236, 0.39653931948230575, -0.7291320908465551,
        0.4697822874053586, 0.14390600392910627, -0.22403618499416572,
        -0.07130921926705004, 0.0806126091510659, 0.03802993693503463,
        -0.01657454163101562, -0.012550998556013784, 0.00042957797300470274,
        0.0018016407039998328, 0.0003537138000010399
    };
    /**
     * Daubechies coefficients of the 8th order Decomposition HPF
     */
    private static Double[] db8 = {
        -0.05441584224308161, 0.3128715909144659, -0.6756307362980128,
        0.5853546836548691, 0.015829105256023893, -0.2840155429624281,
        -0.00047248457399797254, 0.128747426620186, 0.01736930100202211,
        -0.04408825393106472, -0.013981027917015516, 0.008746094047015655,
        0.00487035299301066, -0.0003917403729959771, -0.0006754494059985568,
        -0.00011747678400228192
    };
    /**
     * Daubechies coefficients of the 9th order Decomposition HPF
     */
    private static Double[] db9 = {
        -0.03807794736316728, 0.24383467463766728, -0.6048231236767786,
        0.6572880780366389, -0.13319738582208895, -0.29327378327258685,
        0.09684078322087904, 0.14854074933476008, -0.030725681478322865,
        -0.06763282905952399, -0.00025094711499193845, 0.022361662123515244,
        0.004723204757894831, -0.004281503681904723, -0.0018476468829611268,
        0.00023038576399541288, 0.0002519631889981789, 3.9347319995026124e-05
    };
    /**
     * Daubechies coefficients of the 10th order Decomposition HPF
     */
    private static Double[] db10 = {
        -0.026670057900950818, 0.18817680007762133, -0.5272011889309198,
        0.6884590394525921, -0.2811723436604265, -0.24984642432648865,
        0.19594627437659665, 0.12736934033574265, -0.09305736460380659,
        -0.07139414716586077, 0.02945753682194567, 0.03321267405893324,
        -0.0036065535669883944, -0.010733175482979604, -0.0013953517469940798,
        0.00199240529499085, 0.0006858566950046825, -0.0001164668549943862,
        -9.358867000108985e-05, -1.326420300235487e-05
    };

    /**
     *
     * @param grade
     *
     * @since 2013-08-15
     */
    DecompositionHPF(int grade) {
        if (grade == 2) {
            initialize(db2);
        }
        if (grade == 3) {
            initialize(db3);
        }
        if (grade == 4) {
            initialize(db4);
        }
        if (grade == 5) {
            initialize(db5);
        }
        if (grade == 6) {
            initialize(db6);
        }
        if (grade == 7) {
            initialize(db7);
        }
        if (grade == 8) {
            initialize(db8);
        }
        if (grade == 9) {
            initialize(db9);
        }
        if (grade == 10) {
            initialize(db10);
        }
    }

    /**
     *
     * @param sample
     * @return
     *
     * @since 2013-08-15
     */
    public double filterSample(short sample) {
        return filter(sample);
    }
}
